﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NPinyin;

namespace aier.business.logic
{
    /// <summary>
    /// 中文转首字母大写
    /// </summary>
   public class ChineseToLetterBll
    {
        public string startWithFirst(char firstChar)
        {
            Regex regNumOrChar = new Regex("[0-9a-zA-Z]");
            Regex regChina = new Regex("^[^\x00-\xFF]");
            
            //字母和数字开头
            if (regNumOrChar.IsMatch(firstChar.ToString()))
            {
                return firstChar.ToString().ToUpper();
            }
            //汉字开头
            else if (regChina.IsMatch(firstChar.ToString()))
            {
                string result = Pinyin.GetPinyin(firstChar.ToString());
                return result[0].ToString().ToUpper();
            }
            else
            {
                return "#";
            }

        }
    }
}
